{
 "cells": [
  {
   "cell_type": "markdown",
   "id": "3a79ef54-63e6-429f-ba9f-590b736a7f29",
   "metadata": {},
   "source": [
    "## 2.4 创建符合正态分布的随机张量"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "c90a18b9-d8e8-431c-856c-35f1e4ed05e1",
   "metadata": {},
   "source": [
    "### 1.任务描述\n",
    "- 创建形状为(2,4)，均值为0，标准差为1的正态分布随机张量。\n",
    "- 创建形状为(2,4)，均值为100，标准差为10的正态分布随机张量。\n",
    "- 创建形状为(2,4)，均值为0，标准差为1的截断式正态分布随机张量。"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "8d7baa9c-93a2-42f3-a3c1-231cdb587f2d",
   "metadata": {},
   "source": [
    "### 2.知识准备\n",
    "\n",
    "见教程。\n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "74ad989a-9b82-43e1-b841-e74284cd5936",
   "metadata": {},
   "source": [
    "### 3.任务分析\n",
    "\n",
    "创建正态分布随机张量可以使用tf.random.normal方法；创建截断式正态分布随机张量可以使用tf.random.truncated_normal方法。"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "435c6090-cfda-4f46-a550-22a368e41e4a",
   "metadata": {},
   "source": [
    "### 4.任务实施\n",
    "\n"
   ]
  },
  {
   "attachments": {},
   "cell_type": "markdown",
   "id": "ec75eb6c-5da3-467d-a471-ca3b47242dd6",
   "metadata": {},
   "source": [
    "执行代码"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "2ae9da58-e339-4d22-9f8d-ca255711d89e",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "tf.Tensor(\n",
      "[[ 0.2142097   0.67165387  0.6488827  -0.37174174]\n",
      " [-0.08054236  0.5879414  -0.5981035  -0.10886037]], shape=(2, 4), dtype=float32)\n",
      "tf.Tensor(\n",
      "[[ 80.1326    93.03927   82.65155  112.85316 ]\n",
      " [ 87.675064 106.07642   93.3062   106.386566]], shape=(2, 4), dtype=float32)\n",
      "tf.Tensor(\n",
      "[[-0.24165905  1.1571795   0.19623369  0.36434403]\n",
      " [-1.0018103  -0.15481135 -0.7531855  -0.9894073 ]], shape=(2, 4), dtype=float32)\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "# 创建均值为0，标准差为1的张量\n",
    "re1=tf.random.normal(shape=(2,4),mean=0,stddev=1)\n",
    "# 或\n",
    "re1=tf.random.normal(shape=(2,4))\n",
    "print(re1)\n",
    "# 创建均值为100，标准差为10的张量\n",
    "re2=tf.random.normal(shape=(2,4),mean=100,stddev=10)\n",
    "print(re2)\n",
    "# 创建截断式正态分布随机张量。不超出范围[-2,2]\n",
    "re3=tf.random.truncated_normal(shape=(2,4))\n",
    "print(re3)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "745e27eb-80a5-43fe-acba-d5ddd5fa4de9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (ipykernel)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.10"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
